package io.gitee.yth.design.pattern.test.core.pattern.behavioral.interpreter;

/**
 * @author yth
 * @since 2023-05-01-23:21
 */
public class OrExp implements BooleanExp {

    private final BooleanExp operand1;
    private final BooleanExp operand2;

    public OrExp(BooleanExp operand1, BooleanExp operand2) {
        this.operand1 = operand1;
        this.operand2 = operand2;
    }

    @Override
    public boolean evaluate(Context context) {
        return operand1.evaluate(context) || operand2.evaluate(context);
    }

    @Override
    public BooleanExp replace(String var, BooleanExp exp) {
        return new OrExp(
                operand1.replace(var, exp),
                operand2.replace(var, exp)
        );
    }

    @Override
    public BooleanExp copy() {
        return new OrExp(operand1, operand2);
    }
}
